package com.liy.cloud.base.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.liy.cloud.base.dao.BaseEquParamDao;
import com.liy.cloud.base.entity.BaseEquParamEntity;
import com.liy.cloud.base.service.BaseEquParamService;
import com.das.framework.common.dao.IBaseDao;
import com.das.framework.common.service.impl.BaseServiceImpl;
import com.das.framework.common.utils.Tools;
import com.das.framework.common.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class BaseEquParamServiceImpl extends BaseServiceImpl<BaseEquParamEntity, String> implements BaseEquParamService {

	@Autowired
	private BaseEquParamDao baseEquParamDao;
	
	@Override
	public IBaseDao<BaseEquParamEntity, String> getDao() {
		return baseEquParamDao;
	}




	@Override
	public void deleteBatch(List<String> ids) {
		for (String id : ids) {
			baseEquParamDao.deleteByPrimaryKey(id);
		}
	}

	@Override
	public List<String> selectEquIdGroup() throws Exception {
		return baseEquParamDao.selectEquIdGroup();
	}

	@Override
	public void save(List<BaseEquParamEntity> equParamList, String equId) throws Exception {

		//先删除原有关系，再插入新的关系
		baseEquParamDao.deleteByEquId(equId);
		for(int i=0;i<equParamList.size();i++){
            BaseEquParamEntity baseEquParam = JSON.parseObject(JSONObject.toJSONString(equParamList.get(i),true),BaseEquParamEntity.class);
            baseEquParam.setId(Tools.getNewUUID());
			baseEquParamDao.insertSelective(baseEquParam);
		}
	}

	@Override
	public List<BaseEquParamEntity> selectByTreeNodePage(BaseEquParamEntity var1, PageVO<BaseEquParamEntity> var2) {
		return baseEquParamDao.selectByTreeNodePage(var1, var2);
	}
}
